Skip to content

Conversation

roypat
Copy link
Contributor

@roypat roypat commented Sep 13, 2024

Changes

Removes mocking in net device code. Mocking in rust should not be done using cfg(not(test)), but rather using traits. However, in this specific case, there is no need for mocking, because we already have a separate framework for simulating tap traffic by writing to a socket that is connected to an actual tap device. So just remove mocking and switch the 3 tests that relied on it to this other framework.

Reason

Removes the last major source of cfg(not(test)) in our code base, and will make @bchalios's job easier (or so I've been told)

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this
    PR.
  • API changes follow the Runbook for Firecracker API changes.
  • User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • New TODOs link to an issue.
  • Commits meet
    contribution quality standards.

  • This functionality cannot be added in rust-vmm.

Clippy insists and my pre-commit hook keeps trying to add this to random
commits.

Signed-off-by: Patrick Roy <[email protected]>
Copy link

codecov bot commented Sep 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.35%. Comparing base (6c70ece) to head (845c2f0).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4802      +/-   ##
==========================================
+ Coverage   84.31%   84.35%   +0.03%     
==========================================
  Files         249      249              
  Lines       27521    27512       -9     
==========================================
+ Hits        23205    23207       +2     
+ Misses       4316     4305      -11     
Flag Coverage Δ
5.10-c5n.metal 84.57% <ø> (+0.03%) ⬆️
5.10-m5n.metal 84.55% <ø> (+0.02%) ⬆️
5.10-m6a.metal 83.85% <ø> (+0.03%) ⬆️
5.10-m6g.metal 80.93% <ø> (+0.03%) ⬆️
5.10-m6i.metal 84.55% <ø> (+0.03%) ⬆️
5.10-m7g.metal 80.93% <ø> (+0.03%) ⬆️
6.1-c5n.metal 84.57% <ø> (?)
6.1-m5n.metal 84.55% <ø> (?)
6.1-m6a.metal 83.85% <ø> (?)
6.1-m6g.metal 80.93% <ø> (?)
6.1-m6i.metal 84.55% <ø> (?)
6.1-m7g.metal 80.93% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@roypat roypat force-pushed the no-net-mocking branch 5 times, most recently from 3fc4e71 to ad6a859 Compare September 13, 2024 16:44
@roypat roypat added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Sep 13, 2024
@roypat roypat requested review from ShadowCurse and bchalios and removed request for bchalios September 13, 2024 17:07
Copy link
Contributor

@ShadowCurse ShadowCurse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The test code has two ways to inject a packet to be read from the tap
device: Using the `TapTrafficSimulator`, which actually uses `sendto` to
send something through the tap device, or `MockFrame`, which hijacks
`Net::read_tap` to not actually read from the tap and just return the
packet. Eliminate the latter, as it was only used in a single test, and
needless complicates the test setup (well, arguably, unittests shouldn't
use actual Tap devices, and thus we should eliminte
`TapTrafficSimulator` instead, but I'm choosing my battles today).

Do the injection of the packet before we deplete the ratelimiter, as
otherwise the injection takes long enough for the ratelimiter to
replenish, causing the test to fail intermittently. Also increase the
replenish time.

Signed-off-by: Patrick Roy <[email protected]>
The only use of this implement was its test. Remove both.

Signed-off-by: Patrick Roy <[email protected]>
There was a very elaborate mocking setup in the net device code
involving `cfg(not(test))`, but the only point of it all was to be able
to test the scenario where `tap.write_iovec` or `tap.read` return an
error. We do not need mocking to achieve this though: We can simply
close the tap fd. Thus remove all the mocking, and update the negative
tests to close the fd.

I had half a mind to just delete the tests, as currently we are not
sensibly handling errors in device emulation anyway, so the assertions
these tests make aren't exactly useful. However, once we implement
device reset, this will probably change, so let's keep the tests.

Signed-off-by: Patrick Roy <[email protected]>
This function used an unsound `mem::transmute` to invalidly extend a
lifetime with the goal of creating a self-referential struct. Sadly,
after returning from `get_default`, the `GuestMemoryMmap` gets moved to
a different stack frame, and so all references that this function
created become dangling pointers.

Fix this by not trying to create self-referential struct.

Signed-off-by: Patrick Roy <[email protected]>
@roypat roypat merged commit c86a562 into firecracker-microvm:main Sep 16, 2024
6 of 7 checks passed
@roypat roypat deleted the no-net-mocking branch September 16, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Awaiting review Indicates that a pull request is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants